home *** CD-ROM | disk | FTP | other *** search
- PROGRAM Bubble;
- CONST
- Maxlength = 1000;
- VAR
- size : integer;
- a : ARRAY [1..Maxlength] of integer;
- (* =================================== *)
- PROCEDURE Get_Information;
- VAR
- i : integer;
- BEGIN
- Writeln;
- Writeln(' PASCAL BUBBLE SORT');Writeln;
- Writeln(' ---- A Sample Program for Beginning TURBO Pascal Programmers ----');
- Gotoxy(27,15);
- Writeln('Sorts Up to 1000 Integers');
- Gotoxy(23,19);
- Write('Enter number of digits to be sorted: ');
- Readln(size);Delay(1000);clrscr;
- Writeln(' Type each integer (32767 max) on a line.');writeln;
- FOR i := 1 to size DO
- BEGIN
- Gotoxy(35,12); Write('ENTRY # ',i:4,' : ');Clreol;
- Readln(a[i]);Gotoxy(65,3);Write(size-i:4,' left to go.');
- END;
- END;
- (* =================================== *)
- PROCEDURE Bubble_Sort;
- VAR
- i,q,t : integer;
- BEGIN
- FOR i := size-1 DOWNTO 1 DO
- FOR q := 1 to i DO
- IF a[q] >= a[q+1] THEN
- BEGIN
- t := a[q+1];
- a[q+1] := a[q];
- a[q] := t;
- END
- END;
- (* ================================== *)
- PROCEDURE Printout;
- VAR
- q : integer;
- BEGIN
- Writeln; Writeln;
- FOR q := 1 to size DO
- BEGIN
- Writeln ('Position ',q:3,' is ',a[q]);
- END;
- Writeln;Writeln('TURBO is sure fast, isn''t it!!');
- Writeln; Writeln('══ End of Program ══');
- END;
- (* =================================== *)
- BEGIN (*Main Program*)
- Get_Information;
- Bubble_Sort;
- Printout;
- END.
- ND;
- (* =====